package hlhj.fhp.supreme.customview

import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.widget.LinearLayout
import android.widget.PopupWindow
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import hlhj.fhp.supreme.R
import hlhj.fhp.supreme.javabean.ClassListBean
import kotlinx.android.synthetic.main.class_pop.view.*
import java.util.ArrayList

/**
 * Created by Administrator on 2018\4\24 0024.
 */
class TypePop(private val context: Context,private val datas:ArrayList<ClassListBean.DataBeanX.LevelBean>,private val listener:OnTypeSelectListener) :PopupWindow(){
    init {
        initPop()
    }

    private fun initPop() {
        this.animationStyle= R.style.class_pop_style
        this.width= LinearLayout.LayoutParams.WRAP_CONTENT
        this.height= LinearLayout.LayoutParams.WRAP_CONTENT
        contentView= LayoutInflater.from(context).inflate(R.layout.class_pop,null)


        val adp=object :BaseQuickAdapter<ClassListBean.DataBeanX.LevelBean,BaseViewHolder>(R.layout.his_pop_item,datas){
            override fun convert(helper: BaseViewHolder?, item: ClassListBean.DataBeanX.LevelBean?) {
                helper?.setText(R.id.tv,item?.title)
            }
        }

        contentView.listView.adapter=adp
        contentView.listView.layoutManager=LinearLayoutManager(context,LinearLayout.VERTICAL,false)
        adp.setOnItemClickListener { adapter, view, position ->
            listener.onTypeSelect(datas[position].id.toString(),datas[position].title)
            dismiss()
        }

    }

    interface OnTypeSelectListener{
        fun onTypeSelect(id:String,str:String)
    }
}